import os


class Config:
    # 设置参数
    MYSQL_DIALECT = 'mysql'
    MYSQL_DRIVER = 'pymysql'
    MYSQL_USERNAME = 'root'
    MYSQL_PASSWORD = 'shen0611'
    MYSQL_HOST = 'localhost'
    MYSQL_PORT = 3306
    MYSQL_DB = 'flask_shop'
    MYSQL_CHARSET = 'utf8mb4'

    SQLALCHEMY_DATABASE_URI = f'{MYSQL_DIALECT}+{MYSQL_DRIVER}://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DB}?charset={MYSQL_CHARSET}'

    SECRET_KEY = os.urandom(16)
    DEBUG = True

    # 设置JSON数据不使用ASCII编码
    JSON_AS_ASCII = False
    RESTFUL_JSON = {'ensure_ascii': False}

    # 设置token过期时间
    JWT_EXPIRATION_DELTA = 60 * 60 * 24 * 7     # 7天

    # 设置可以上传分图片类型
    ALLOWED_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif']
    # 获取当前项目路径
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    # 设置图片上传的路径
    UPLOAD_FOLDER = os.path.join(BASE_DIR, 'flask_shop', 'static/upload')


class DevelopmentConfig(Config):
    # 开发环境
    DEBUG = True


class ProductionConfig(Config):
    # 生产环境
    DEBUG = False


class TestingConfig(Config):
    # 测试环境
    DEBUG = True


config_map = {
    'develop': DevelopmentConfig,
    'product': ProductionConfig,
    'test': TestingConfig
}
